package com.bwie.parkdemo.mvvm.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.bwie.lib_core.action.ActActionField;
import com.bwie.lib_core.mvvm.base.BaseActivity;
import com.bwie.parkdemo.BR;
import com.bwie.parkdemo.R;
import com.bwie.parkdemo.databinding.ActivityParkingallBinding;
import com.bwie.parkdemo.mvvm.model.entity.AddSysParkingEntity;
import com.bwie.parkdemo.mvvm.model.entity.ParkingAllEntity;
import com.bwie.parkdemo.mvvm.viewmodel.ParkingAllViewModel;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * 全部车位activity
 * */
public class ParkingAllActivity extends BaseActivity<ActivityParkingallBinding, ParkingAllViewModel> {
    @Override
    public int initLayout() {
        return R.layout.activity_parkingall;
    }

    @Override
    public void initView() {
        EventBus.getDefault().register(this);
        //获取启动参数
        Bundle bundle = getIntent().getBundleExtra(ActActionField.ACTBUNDLE);
        boolean resultFlag = false;
        if (bundle!=null)
            resultFlag = bundle.getBoolean(ActActionField.FORRESULT);
        vm.resultFlag = resultFlag;//添加是否设置返回值
    }

    @Override
    public int initVariable() {
        return BR.vm;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refreshParking(AddSysParkingEntity entity){
        vm.refreshParkingAll();
    }

    //eventbus 获取用户选择的车位回传给对应的来访申请界面
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void selParking(ParkingAllEntity.Values entity){
        Log.e("ZXWQ","selParking:"+entity.parkId);
        //设置返回值
        Bundle bundle = new Bundle();
        bundle.putInt("parkId",entity.parkId);
        bundle.putString("parkName",entity.parkName);
        Intent intent = new Intent();
        intent.putExtra(ActActionField.ACTBUNDLE,bundle);
        setResult(RESULT_OK,intent);
        finish();
    }

}
